/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.informet.ipd.modelo.dao;

import com.informet.ipd.modelo.vo.ProgEstrMarLogVO;
import com.informet.ipd.modelo.vo.ProgEstrVO;
import com.informet.ipd.modelo.vo.RolUsuarioVO;
import com.informet.ipd.modelo.vo.UsuarioVO;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author LAPTOP01
 */
public class ProgEstrMarLogDaoFinMeta extends DBase{


  Connection conn = null;

    public ProgEstrMarLogDaoFinMeta() {
        super();
    }

    public void  setDetailMarLogFinMeta(ProgEstrMarLogVO bean, ResultSet rs) throws SQLException{
        bean.setCodUpdate(rs.getInt("NUM_METAFINPRG_PK"));
        bean.setDESC_META(rs.getString("TX_DESCMETAFINPRG"));
        bean.setCANT_META(rs.getInt("NUM_CANTMETAFINPRG"));
        bean.setTIPO_META(rs.getString("TX_TIPOMETAFINPRG"));
    }

    public void  setMetaFinPI(ProgEstrMarLogVO bean, ResultSet rs) throws SQLException{
        bean.setCodUpdate(rs.getInt("NUM_METAFINPRY_PK"));
        bean.setDESC_META(rs.getString("TX_DESCMETAFINPRY"));
        bean.setCANT_META(rs.getInt("NUM_CANTMETAFINPRY"));
        bean.setTIPO_META(rs.getString("TX_TIPOMETAFINPRY"));
    }

     public void  setDetailMarLogPropositoMeta(ProgEstrMarLogVO bean, ResultSet rs) throws SQLException{

        bean.setCodUpdate(rs.getInt("NUM_METAPROPPRG_PK"));
        bean.setDESC_META(rs.getString("TX_DESCMETAPROPPRG"));
        bean.setCANT_META(rs.getInt("NUM_CANTMETAPROPPRG"));
        bean.setTIPO_META(rs.getString("TX_TIPOMETAPROPPRG"));
    }

      public void  setDetailMarLogComponenteMeta(ProgEstrMarLogVO bean, ResultSet rs) throws SQLException{
        bean.setCodUpdate(rs.getInt("NUM_METAPROPPRG_PK"));
        bean.setDESC_META(rs.getString("TX_DESCMETACOMPPRG"));
        bean.setCANT_META(rs.getInt("NUM_CANTMETACOMPPRG"));
        bean.setTIPO_META(rs.getString("TX_TIPOMETACOMPPRG"));
        
    }



 
     public List getlistMarLogFinMeta(int codPrograma) throws SQLException {

        Statement stmt = null;
        ResultSet rs = null;
        ArrayList<ProgEstrMarLogVO> lista = new ArrayList<ProgEstrMarLogVO>(0);
        //List lista=null;
        //lista=null;
        String sql = "";
        try {
            conn = DriverManager.getConnection(url, usuario, password);
            stmt = conn.createStatement();
           sql =" select   "+
                   "  f.*   "+
                   " from me_metafinprg f   "+
                   " where   f.num_finprg_pk="+codPrograma;
            
            rs = stmt.executeQuery(sql);
            ProgEstrMarLogVO bean = null;
            while (rs.next()) {
                bean = new ProgEstrMarLogVO();
               setDetailMarLogFinMeta(bean, rs);
               lista.add(bean);
            }

        } finally {
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
                stmt.close();
                stmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }

        }
        return lista;
    }




     public List getlistMetaFinPI(int codPrograma) throws SQLException {

        Statement stmt = null;
        ResultSet rs = null;
        ArrayList<ProgEstrMarLogVO> lista = new ArrayList<ProgEstrMarLogVO>(0);
        //List lista=null;
        //lista=null;
        String sql = "";
        try {
            conn = DriverManager.getConnection(url, usuario, password);
            stmt = conn.createStatement();
           sql =" select   "+
                   "  f.*   "+
                   " from ME_METAFINPYINV f   "+
                   " where   f.NUM_FINPRY_PK="+codPrograma;

            rs = stmt.executeQuery(sql);
            ProgEstrMarLogVO bean = null;
            while (rs.next()) {
                bean = new ProgEstrMarLogVO();
               setMetaFinPI(bean, rs);
               lista.add(bean);
            }

        } finally {
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
                stmt.close();
                stmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }

        }
        return lista;
    }


     public List getlistMarLogComponenteMeta(int codPrograma) throws SQLException {

        Statement stmt = null;
        ResultSet rs = null;
        ArrayList<ProgEstrMarLogVO> lista = new ArrayList<ProgEstrMarLogVO>(0);
        //List lista=null;
        //lista=null;
        String sql = "";
        try {
            conn = DriverManager.getConnection(url, usuario, password);
            stmt = conn.createStatement();
            sql =" select    "+
                  "  c.*  "+
                  " from me_metacompprg c "+
                  " where  c.num_metacompprg_pk="+codPrograma;

            rs = stmt.executeQuery(sql);
            ProgEstrMarLogVO bean = null;
            while (rs.next()) {
                bean = new ProgEstrMarLogVO();
               setDetailMarLogComponenteMeta(bean, rs);
               lista.add(bean);
            }

        } finally {
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
                stmt.close();
                stmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }

        }
        return lista;
    }


     public List getlistMarLogPropositoMeta(int codPrograma) throws SQLException {

        Statement stmt = null;
        ResultSet rs = null;
        ArrayList<ProgEstrMarLogVO> lista = new ArrayList<ProgEstrMarLogVO>(0);
        //List lista=null;
        //lista=null;
        String sql = "";
        try {
            conn = DriverManager.getConnection(url, usuario, password);
            stmt = conn.createStatement();
            sql =" select "+
                   "  p.*  "+
                  " from me_metapropprg p "+
                  " where  p.num_metapropprg_pk="+codPrograma;


            rs = stmt.executeQuery(sql);
            ProgEstrMarLogVO bean = null;
            while (rs.next()) {
                bean = new ProgEstrMarLogVO();
               setDetailMarLogPropositoMeta(bean, rs);
               lista.add(bean);
            }

        } finally {
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
                stmt.close();
                stmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }

        }
        return lista;
    }

      public String spMan(ProgEstrMarLogVO bean) {
        String msj = "";
        //int codP=bean.getCODPRG();
        try {
            conn = DriverManager.getConnection(url, usuario, password);
            CallableStatement cs = conn.prepareCall("{call Man_ProgEstrFinMeta(?,?,?,?,?,?)}");
            cs.setString(1,bean.getOpcion());
            cs.setString(2, bean.getDESC_META());
            cs.setInt(3, bean.getCANT_META());
            cs.setString(4, bean.getTIPO_META());
            cs.setInt(5, bean.getCodUpdate());
            cs.setInt(   6, bean.getCODPRG());
            cs.execute();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.toString());
            msj = e.toString();
            return msj;
        }
        return msj;
    }


      public String spManI(ProgEstrMarLogVO bean) {
        String msj = "";
        //int codP=bean.getCODPRG();
        try {
            conn = DriverManager.getConnection(url, usuario, password);
            CallableStatement cs = conn.prepareCall("{call Man_ProgInvFinMeta(?,?,?,?,?,?)}");
            cs.setString(1,bean.getOpcion());
            cs.setString(2, bean.getDESC_META());
            cs.setInt(3, bean.getCANT_META());
            cs.setString(4, bean.getTIPO_META());
            cs.setInt(5, bean.getCodUpdate());
            cs.setInt(   6, bean.getCODPRG());
            cs.execute();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.toString());
            msj = e.toString();
            return msj;
        }
        return msj;
    }

}
